Skip to content

fix: guard ProgressBar/Meter percentage against NaN when min equals max#10169

Merged
LFDanLu merged 4 commits into
adobe:mainfrom
mvanhorn:fix/10042-progressbar-meter-nan-percentage
Jun 26, 2026
Merged

fix: guard ProgressBar/Meter percentage against NaN when min equals max#10169
LFDanLu merged 4 commits into
adobe:mainfrom
mvanhorn:fix/10042-progressbar-meter-nan-percentage

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

ProgressBar and Meter no longer emit NaN% when minValue equals maxValue.

Why this matters

Reported in #10042: when minValue === maxValue, the percentage calculation (value - minValue) / (maxValue - minValue) divides by zero and produces NaN, which surfaced both in the rendered width and the aria-valuetext percent label. The fix treats a zero range as 0% and supplies a 0% value label so assistive tech reads a real value.

Changes

  • Guard the percentage against a zero range in both ProgressBar and Meter.
  • When the range is zero and no explicit valueLabel is set, format 0 with the percent formatter so the label is 0% instead of NaN%.

Testing

Added ProgressBar and Meter tests for the minValue === maxValue case.

Fixes #10042

AI was used for assistance.

@snowystinger

Copy link
Copy Markdown
Member

Thanks for the PR. Which of these cases have you tried out and what were the results? #10042 (comment)

@snowystinger snowystinger added the waiting Waiting on Issue Author label Jun 25, 2026
snowystinger
snowystinger previously approved these changes Jun 26, 2026

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test instructions:

run s2-docs
go to the Values section for Meter and ProgressBar, there is a control for min/max, set them to 0
navigate to the component with AT

I had some trouble with VO not navigating correctly inside storybook. So the docs are better for it.

In theory I'm fine with it. But we'll need to do some testing with assistive technologies. Here's a general list we'll want to check out:

  • Safari + VO
  • Chrome + VO
  • iOS Safari + VO

@snowystinger snowystinger added ready for review and removed waiting Waiting on Issue Author labels Jun 26, 2026
@LFDanLu
LFDanLu added this pull request to the merge queue Jun 26, 2026
Merged via the queue into adobe:main with commit e6c47b5 Jun 26, 2026
29 checks passed
jsmitrah pushed a commit to jsmitrah/react-spectrum that referenced this pull request Jun 29, 2026
…ax (adobe#10169)

* fix: guard ProgressBar/Meter percentage against NaN when min equals max

* simplify, fix hooks, and fix v3

* fix lint

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Robert Snow <rsnow@adobe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProgressBar and Meter produce NaN percentage when minValue === maxValue

4 participants